package org.swingplus.core.scanner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swingplus.core.annotation.Style;
import org.swingplus.core.annotation.layout.Layout;
import org.swingplus.core.annotation.widget.Frame;
import org.swingplus.core.annotation.widget.Widget;
import org.swingplus.core.bean.MetaData;
import org.swingplus.core.bean.MetaDataType;
import org.swingplus.core.util.AnnoManageUtil;
import org.swingplus.core.widget.WidgetActvity;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

public class AutowiredScan extends ComponentScan{
    private static final Logger logger= LoggerFactory.getLogger(AutowiredScan.class);


    public static void widgetScan(Class<?> clazz){

        String packageName=clazz.getPackage().getName();
        logger.info("packageName:{}",packageName);
        System.out.println("packageName:"+packageName);
        packageName ="";
        
        //TODO 方便排查问题先去掉for循环
//        @SuppressWarnings("rawtypes")
//		Class[] widgetcollect = WidgetConstant.widgetCollect;
//        for (int i = 0; i < widgetcollect.length; i++) {
//        	Class widget = widgetcollect[i];
//        	AnnoManageUtil.getAnnotationType(packageName, widget);
//		}
//      
        MetaData metaData=AnnoManageUtil.getAnnotationType(packageName, Frame.class);


        for (MetaDataType metaDataType: metaData.getInstanceType()){

            WidgetActvity.specifyAttribute(metaDataType.getInstance(),"setUndecorated",metaDataType.getAnnotationsType());
            Map<Field,Annotation[]> fieldAnnotations =metaDataType.getMap();
            for (Field field : fieldAnnotations.keySet()) {
                Annotation[] annotations=fieldAnnotations.get(field);
//            logger.info("field================");
                logger.info("field：{}",field.getName());
                WidgetActvity.specifyAttribute(metaDataType.getInstance(),field,annotations);
            }
            ListenerScan.listenerScan(metaDataType.getInstance());

        }

//        MainFrame2 dddd=(MainFrame2)metaData.getInstance();

//        dddd.initComponents();
//        dddd.initView();
//        dddd.setListeners();
//        dddd.setVisible(true);


//        fieldAnnotations.
        
        
        
        
        
        

        
        
//        AnnoManageUtil.getAnnotationType(packageName, Button.class);
//
//        AnnoManageUtil.getAnnotationType(packageName, Panel.class);


//        Annotation[] annotations = AnnoManageUtil.getAnnotationType(packageName, Frame.class);
//        for (int i = 0; i <annotations.length ; i++) {
//            System.out.println(annotations[i].annotationType().getName());
//        }
    }

    public static Map<Class,List<Object>> scan(Map<Class,List<Object>> map){

        List<Object> objects = map.get(Layout.class);
        AnnoManageUtil.autowired(objects);

        objects = map.get(Style.class);
        AnnoManageUtil.autowired(objects);

        objects = map.get(Widget.class);
        AnnoManageUtil.autowired(objects);
        //通讯组件扫描构建
        AnnoManageUtil.internal(objects);

        return null;

    }



}
